package com.tengju.motivation.domain.model.activity;

import lombok.AllArgsConstructor;


@AllArgsConstructor
public enum UserLevel {

    /* 没有等级（游客） */
    NONE(0L, "游客"),

    /* 注册用户 */
    NORMAL(1L, "注册用户"),

    /* VIP */
    VIP(2L, "粉卡"),

    /* VVIP */
    VVIP(3L, "白金卡"),

    /* SVIP */
    SVIP(4L, "黑钻卡"),

    /* 黑卡 */
    BLACK(5L, "黑钻PLUS");

    private final Long val;
    private final String desc;

    public Long getVal() {
        return val;
    }

    public String getDesc() {
        return desc;
    }

    public static UserLevel fromVal(Integer val) {
        return fromVal(Long.valueOf(val));
    }
    public static UserLevel fromVal(Long val) {
        for (UserLevel type : values()) {
            if (type.val.equals(val)) {
                return type;
            }
        }
        return null;
    }

    public static UserLevel fromName(String name) {
        for (UserLevel type : values()) {
            if (type.name().equals(name)) {
                return type;
            }
        }
        return null;
    }

    public boolean isLower(UserLevel targetGrownUserLevel) {
        if (targetGrownUserLevel == null) {
            return true;
        }
        return this.getVal() < targetGrownUserLevel.getVal();
    }
}
